home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / dev / e / amigae21b.lha / Amiga_E_v2.1b / Sources / Utilities / Pragma2Module.e < prev    next >
Text File  |  1992-09-02  |  3KB  |  110 lines

  1. /* Pragma2Module
  2.    convert a SAS/C library pragma file to an E module.
  3.    Usage: p2m <file>
  4.    converts <file.h> to <file.m>                                  */
  5.    
  6. ENUM INPUT_ERROR=10,OUTPUT_ERROR,FORMAT_ERROR
  7.  
  8. DEF cfh,efh,eof,
  9.     gotbase=FALSE,
  10.     offset=30,
  11.     cfile[200]:STRING,
  12.     efile[200]:STRING,
  13.     cstring[200]:STRING
  14.  
  15. PROC main()
  16.   StrCopy(cfile,arg,ALL)
  17.   StrAdd(cfile,'.h',ALL)
  18.   StrCopy(efile,arg,ALL)
  19.   StrAdd(efile,'.m',ALL)
  20.   WriteF('Amiga E Pragma2Module by $#%! in 1992\nconverting: "\s"\n',cfile)
  21.   IF (cfh:=Open(cfile,OLDFILE))=0 THEN closeall(INPUT_ERROR)
  22.   IF (efh:=Open(efile,NEWFILE))=0 THEN closeall(OUTPUT_ERROR)
  23.   REPEAT
  24.     eof:=ReadStr(cfh,cstring)
  25.     convert(cstring)
  26.   UNTIL eof
  27.   WriteF('last offset: -\d\n',offset)
  28.   Out(efh,$FF)
  29.   WriteF('Done.\n')
  30.   closeall(0)
  31. ENDPROC
  32.  
  33. PROC closeall(er)
  34.   IF cfh<>0 THEN Close(cfh)
  35.   IF efh<>0 THEN Close(efh)
  36.   SELECT er
  37.     CASE INPUT_ERROR;  WriteF('Could not open input file!\n')
  38.     CASE OUTPUT_ERROR; WriteF('Could not open output file!\n')
  39.     CASE FORMAT_ERROR; WriteF('Pragma file format error!\n')
  40.   ENDSELECT
  41.   CleanUp(er)
  42. ENDPROC
  43.  
  44. /* format of line to convert:
  45.    #pragma libcall <lib>Base <funcname> <hexoffset> <regsused>     */
  46.  
  47. PROC convert(str)
  48.   DEF pos,pos2,off2,len,narg,a,empty,dstr[50]:STRING,basestr[50]:STRING
  49.   DEF funcstr[50]:STRING,regstr[20]:STRING,libstr[50]:STRING
  50.   IF StrCmp(str,'#pragma libcall ',STRLEN)        /* just those lines */
  51.     pos:=STRLEN
  52.     pos2:=InStr(str,' ',pos)                      /* find base */
  53.     IF pos2=-1 THEN closeall(FORMAT_ERROR)
  54.     IF gotbase=FALSE                              /* get base */
  55.       gotbase:=TRUE
  56.       MidStr(basestr,str,pos,pos2-pos)
  57.       LowerStr(basestr)
  58.       WriteF('Base will be: \s\n',basestr)
  59.       WriteF('Correct name of this library (with the ".library" or ".device"):\n>')
  60.       ReadStr(stdout,libstr)
  61.       Write(efh,["EM","OD",6]:INT,6)
  62.       Write(efh,libstr,EstrLen(libstr)+1)
  63.       Write(efh,basestr,EstrLen(basestr)+1)
  64.     ENDIF
  65.     pos:=pos2+1
  66.     pos2:=InStr(str,' ',pos)                 /* find func */
  67.     IF pos2=-1 THEN closeall(FORMAT_ERROR)
  68.     MidStr(funcstr,str,pos,pos2-pos)
  69.     IF funcstr[0]>="a" THEN funcstr[0]:=funcstr[0]-32  /* Func, not fUnc */
  70.     IF funcstr[1]<"a" THEN funcstr[1]:=funcstr[1]+32
  71.     str[pos2]:="$"
  72.     UpperStr(str+pos2)
  73.     off2:=Val(str+pos2,NIL)                      /* get offset */
  74.     IF off2=0 THEN closeall(FORMAT_ERROR)
  75.     empty:=0
  76.     WHILE off2<>offset
  77.       Write(efh,'Dum',3)                     /* "empty function slots" */
  78.       Out(efh,16)
  79.       offset:=offset+6
  80.       INC empty
  81.       IF offset>off2 THEN closeall(FORMAT_ERROR)
  82.     ENDWHILE
  83.     IF empty>0 THEN  WriteF('found \d empty or private functions before -\d.\n',empty,offset)
  84.     pos2:=InStr(str,' ',pos2+1)              /* find offset/regs */
  85.     IF pos2=-1 THEN closeall(FORMAT_ERROR)
  86.     pos:=pos2+1
  87.     MidStr(dstr,str,pos,ALL)
  88.     Write(efh,funcstr,EstrLen(funcstr))
  89.     len:=EstrLen(dstr)
  90.     narg:=Val(dstr+len-1,NIL)
  91.     IF len>2
  92.       IF len-2<narg THEN StrCopy(regstr,'0',ALL)
  93.       StrAdd(regstr,dstr,len-2)
  94.     ELSE
  95.       StrCopy(regstr,'',ALL)
  96.     ENDIF
  97.     len:=EstrLen(regstr)
  98.     StrCopy(dstr,'$ ',ALL)
  99.     IF len>0
  100.       FOR a:=1 TO len
  101.         dstr[1]:=regstr[len-a]
  102.         Out(efh,Val(dstr,NIL))
  103.       ENDFOR
  104.     ELSE
  105.       IF narg=0 THEN Out(efh,16) ELSE Out(efh,0)
  106.     ENDIF
  107.     offset:=offset+6
  108.   ENDIF
  109. ENDPROC
  110.